// 引入 react 依赖
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { Text, View, Image, TouchableOpacity, Alert, ImageBackground, ScrollView, TextInput, Picker } from 'react-native';

// 引入第三方依赖
import _ from 'lodash';
import pureRender from 'pure-render-decorator';
import { Actions } from 'react-native-router-flux';

// antd 按需加载
import { Tabs, Toast } from '@ant-design/react-native';

// 引入 处理数据 所需文件
import { } from './module/module.js'
import { sendAuthCode } from '../module.js'

// 引入样式
import Style from './style/style.js';

// 引入公用组件
import { Status, NavBar } from '../../components/index.js'

// 引入专用组件
import { } from './components'

// 引入工具包
import { press, size, ScreenWidth, validation } from '../../util/utils.js'
class CodeLogin extends Component {
  constructor(props) {
    super(props)
    this.state = {
      send: '获取验证码',
      language: '',
      disable: false,
      checkSjh: null,
      checkSjhVisible: false,
      info: '',
    };
    this.sendAuthCode = sendAuthCode.bind(this)
  }

  handleAuthCode() {
    const { disable } = this.state
    if (!this.telephone._lastNativeText) {
      Toast.info(this.telephone.props.placeholder, 1, null, false);
      return
    }

    if (!validation.phone(this.telephone._lastNativeText)) {
      Toast.info('请输入9-11位手机号', 1, null, false);
      return
    }

    if (disable) {
      return
    }

    this.sendAuthCode({
      countryCode: '+86',
      telephone: this.telephone._lastNativeText,
    })
  }

  render() {
    const { send } = this.state
    return (
      <View style={Style.container}>
        <Status />
        <NavBar
          title="验证码登录"
          back={true}
        />
        <ScrollView style={{ flex: 1, }}>
          <View style={{
            marginTop: 30
          }}>
            <View style={{
              padding: size(30),
            }}
            >
              <View style={{
                flexDirection: 'row',
                alignItems: 'center',
                borderBottomWidth: 1,
                borderBottomColor: '#ececee',
                marginTop: 30,
              }}
              >
                <Picker
                  selectedValue={this.state.language}
                  style={{ height: 50, width: 100 }}
                  onValueChange={(itemValue, itemIndex) => this.setState({ language: itemValue })}>
                  <Picker.Item label="Java" value="java" />
                  <Picker.Item label="JavaScript" value="js" />
                </Picker>
                <TextInput
                  ref={(r) => this.telephone = r}
                  // autoFocus
                  keyboardType="numeric"
                  placeholder="请输入手机号"
                  placeholderTextColor="#c8c8ca"
                  style={{
                    flex: 1,
                    fontSize: 16,
                    paddingVertical: 16,
                    borderWidth: 0,
                    paddingHorizontal: 5,
                    color: '#3e3e3e',
                  }}
                  underlineColorAndroid="transparent"
                />
              </View>
              <View style={{
                flexDirection: 'row',
                alignItems: 'center',
                borderBottomWidth: 1,
                borderBottomColor: '#ececee',
              }}
              >
                <TextInput
                  ref={(r) => this.authCode = r}
                  placeholder="请输入验证码"
                  placeholderTextColor="#c8c8ca"
                  style={{
                    flex: 1,
                    fontSize: 16,
                    paddingVertical: 16,
                    borderWidth: 0,
                    paddingHorizontal: 5,
                    color: '#3e3e3e',
                  }}
                  underlineColorAndroid="transparent"
                />
                <TouchableOpacity
                  onPress={() => this.handleAuthCode()}
                >
                  <Text style={{ fontSize: 14, color: '#61676F', lineHeight: 16, }}>{send}</Text>
                </TouchableOpacity>
              </View>
              <TouchableOpacity
                activeOpacity={0.9}
                onPress={() => {

                }}
                style={{
                  marginTop: 40,
                  paddingVertical: 14,
                  paddingHorizontal: 20,
                  backgroundColor: '#f23030',
                  borderRadius: 23,
                  alignItems: 'center',
                  justifyContent: 'center',
                }}
              >
                <Text style={{ fontSize: size(28), color: '#fff', lineHeight: size(30), }}>登录</Text>
              </TouchableOpacity>
              <View style={{
                flexDirection: 'row',
                justifyContent: 'space-between',
                alignItems: 'center',
                marginTop: 15
              }}>
                <TouchableOpacity
                  onPress={() => Actions.login()}
                >
                  <Text style={{ fontSize: 14, color: '#61676F', lineHeight: 16, }}>密码登录</Text>
                </TouchableOpacity>
                <TouchableOpacity
                  onPress={() => Actions.registered()}
                >
                  <Text style={{ fontSize: 14, color: '#61676F', lineHeight: 16, }}>注册</Text>
                </TouchableOpacity>
              </View>
            </View>
          </View>
        </ScrollView>
      </View >
    );
  }
}


export default connect(({ user }) => ({
  user,
}))(pureRender(CodeLogin))
